package com.then.architecture;


import android.arch.lifecycle.Lifecycle;
import android.arch.lifecycle.LifecycleOwner;
import android.arch.lifecycle.LifecycleRegistry;

import com.luojilab.component.componentlib.router.Router;
import com.luojilab.component.componentlib.router.ui.UIRouter;
import com.then.architecture.mvp.databind.DataBindFragment;
import com.then.architecture.mvp.delegate.AppDelegate;

import org.greenrobot.eventbus.EventBus;

/**
 * Created by 42524 on 2018/1/17.
 */

public abstract class BaseFragment<T extends AppDelegate> extends DataBindFragment<T> implements BuildConfigCallback, LifecycleOwner {

    private final LifecycleRegistry lifecycleRegistry = new LifecycleRegistry(this);


    protected Router router = Router.getInstance();

    protected UIRouter uiRouter = UIRouter.getInstance();


    @Override
    public Lifecycle getLifecycle() {
        return lifecycleRegistry;
    }

    protected void registEventbus() {
        if (!EventBus.getDefault().isRegistered(this)) {
            EventBus.getDefault().register(this);
        }
    }

    protected void unRegistEventbus() {
        if (EventBus.getDefault().isRegistered(this)) {
            EventBus.getDefault().unregister(this);
        }
    }
}
